package com.kiwi.cases.login;

import com.kiwi.action.LoginAction;
import com.kiwi.constant.Constant;
import com.kiwi.constant.ConstantURL;
import com.kiwi.dao.IndianaDao;
import com.kiwi.util.EncryptSet.Impl.SignatureServiceImpl;
import com.kiwi.util.EncryptSet.Interface.SignatureService;
import com.kiwi.util.RedisUtil;
import com.netease.shockwave.http.HttpHandler;
import com.netease.shockwave.testng.ShockwaveTestNG;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 测试接口：重置密码接口 http://uc.s.kiwi.com/api/resetPassword
 *
 *
 * @author xietingting
 */
public class ResetPassword extends ShockwaveTestNG
{
    private  Logger logger = Logger.getLogger(ResetPassword.class);
    @Autowired
    private RedisUtil redisUtil;
    @BeforeClass
    public void BeforeClassTest()
    {
        logger.info("客户端：重置密码测试开始");

    }

    @Test(description = "客户端重置密码接口测试", dataProvider = "ResetPasswordData")
    public void test(String mobile,String newPassword,String verifyCode) throws Exception {
        String param = String.format("mobile=%s&newPassword=%s&verifyCode=%s", mobile,
                newPassword,verifyCode);
        SignatureServiceImpl signatureService = new SignatureServiceImpl();
        String params = signatureService.encodeStr(param);
        HashMap<String, String> params_reg = new HashMap<String, String>();
        params_reg.put("id", Constant.id);
        params_reg.put("deviceId", Constant.deviceId);
        params_reg.put("params", params);
        HttpHandler handler = HttpHandler.getInstance();
        String enResult = handler.usingPostMethod(ConstantURL.RESETPASSWORDURL, params_reg, null);
        logger.info(enResult);
        //delRegInfo(mobile);

    }
    void delRegInfo(String mobile){
        logger.info(redisUtil.get(Constant.USERINFO_BY_LOGINID_PREFIX+mobile));
        logger.info(redisUtil.del(Constant.USERINFO_BY_LOGINID_PREFIX+mobile));
        IndianaDao indianaDao = (IndianaDao) applicationContext.getBean("IndianaDao");
        HashMap<String, String> userInfo= (HashMap<String, String>)indianaDao.selectOne("UserInfoMapper.SelectUserInfo", mobile);
        if(userInfo!=null) {
            String account_id = userInfo.get("account_id");
            String login_id = userInfo.get("login_id");
            logger.info(account_id + " :" + login_id);
        }
        indianaDao.delete("UserInfoMapper.delectUserInfo", mobile);

    }

    @DataProvider(name = "ResetPasswordData")
    public static Object[][] data(){
        return new Object[][]{
                { "18501378016","123456a","123456"}, };
    }

    @AfterClass
    public void AfterClassTest()
    {

        logger.info("客户端：重置密码测试结束");
    }


}
